// pages/mine/huishougoods.js
Page({

  data: {   url:'',url1:'',name:'',phone:'',address:'',content:'',pic:'',phoneflag:false

  },

  onLoad: function (options) {

  },
  upload(){
    wx.chooseImage({
      count:1,
      complete: (res) => {
        console.log(res);
          this.setData({
            url:res.tempFiles[0].path
          })
          wx.uploadFile({
            filePath: res.tempFiles[0].path,
            name: 'file',
            url: 'https://zujieba.com/index/upload/upload.html',
            success:(res1)=>{
              console.log(res1);
              let data=JSON.parse(res1.data)
              let url1=data.name
              this.setData({
                url1
              })
            }
          })
      },
    })
  },
  del(){
      this.setData({
        url:''
      })
  },
  change2(e){
    this.setData({
      name:e.detail.value
    })
  },
  change3(e){
     this.setData({
       phone:e.detail.value
     })
  let phoneflag=this.checkMobile(e.detail.value)
  this.setData({
    phoneflag
  })
  },
  change8(e){
    this.checkMobile1(e.detail.value)
  },
  change4(e){
    this.setData({
      address:e.detail.value   
    })
  },
  change5(e){
    this.setData({
      content:e.detail.value
    })
  },
  suretijiao(){
    if(this.data.phoneflag==false){return wx.showToast({
      title: '请输入正确的手机号',
      icon:'none',
    })}
    if(this.data.name==''||this.data.phone==''||this.data.address==''||this.data.content==''||this.data.url1==''||this.data.phoneflag==false){
      return wx.showToast({
        title: '请填写完整',
      })
    }
    wx.request({
      url: 'https://zujieba.com/Api/buyback/buyback.html',
      data:{name:this.data.name,phone:this.data.phone,address:this.data.address,content:this.data.content,pic:this.data.url1,uid:wx.getStorageSync('uid')},
      success:(res)=>{
        console.log(res);
         if(res.data.success==1){
           wx.showToast({
             title: res.data.tips,
           })
           wx.navigateBack({
             complete: (res) => {},
           })
         }
      }
    })
  },
  checkMobile(e){
    
    if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(e))){
       
        
        return false;
    }
    else{
      return true
    }
},
checkMobile1(e){
    
  if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(e))){
      wx.showToast({
        title: '请输入正确的手机号',
        icon:'none'
      })
      
      return false;
  }
  else{
    return true
  }
}
   
})